<?php
    $this->layout('base.phtml', [
        'title' => _('Discover collections'),
        'canonical' => url_full('discovery'),
        'current_tab' => 'feeds',
        'open_graph' => [
            'title' => _('Discover collections'),
            'description' => _f('Discover the public collections on %s.', get_app_configuration('brand')),
            'locale' => get_current_locale(),
            'url' => url_full('discovery'),
        ],
        'back_options' => [
            'reset' => true,
        ],
    ]);
?>

<div class="section section--longbottom">
    <div class="section__title">
        <h1><?= _('Discover collections') ?></h1>
    </div>

    <?php if ($topics): ?>
        <p class="section__intro"><?= _('Choose a topic…') ?></p>

        <div class="cards cards--centered">
            <?php foreach ($topics as $topic): ?>
                <div class="card card--illustrated" style="background-image: url('<?= url_media('cards', $topic->image_filename) ?>');">
                    <a class="card__body card__body--large" href="<?= url('topic', ['id' => $topic->id]) ?>">
                        <h2 class="card__title card__title-ellipsis">
                            <?= protect($topic->label) ?>
                        </h2>

                        <p class="card__text card__text--small-margin">
                            <?php $number_collections = $topic->countPublicCollections(); ?>
                            <?php if ($number_collections > 0): ?>
                                <?= _nf('%s collection', '%s collections', $number_collections, format_number($number_collections)) ?>
                            <?php else: ?>
                                <?= _('No collections') ?>
                            <?php endif; ?>
                        </p>
                    </a>
                </div>
            <?php endforeach; ?>
        </div>
    <?php else: ?>
        <p class="paragraph--placeholder">
            <?= _('There’s no topics to show.') ?>
        </p>
    <?php endif; ?>
</div>
